// useModal.ts
import { useState } from "react";
import { ModalProps } from "antd";

interface UseModalReturnType<T = any> {
  modalProps: ModalProps & { modalData?: T };
  openModal: (data: Partial<ModalProps> & { modalData?: T }) => void;
  closeModal: () => void;
}

export function useModal<T = any>(initialProps?: Partial<ModalProps>): UseModalReturnType<T> {
  const [modalProps, setModalProps] = useState<ModalProps & { modalData?: T }>({
    open: false,
    ...initialProps,
  });

  const openModal = (data: Partial<ModalProps> & { modalData?: T }) => {
    setModalProps(prev => ({
      ...prev,
      ...data,
      open: true,
    }));
  };

  const closeModal = () => {
    setModalProps(prev => ({
      ...prev,
      open: false,
    }));
  };

  return { modalProps, openModal, closeModal };
}